| No. | Answer | Remark | |
|---|---|---|---|
| 1 | j | None of the Above | |
| 2 | b d g h | strictfp super goto native | Both "const" and "goto" are java keywords, but neither is used. |
| 3 | b c e g i | boolean short const instanceof goto | Both "const" and "goto" are java keywords, but neither is used. |
| 4 | e | None of the Above | String literals are declared using double quotes but all of the declarations here use single quotes. |
| 5 | d | Prints: 0 | Member variables are initialized automatically. Type int variables are initialized to zero. |
| 6 | b c e | Compiler error at line 4. Compiler error at line 5. Compiler error at line 7. | The escape sequences are defined in section 3.10.6 of the Java Language Specification. |
| 7 | a e | transient volatile | Both "const" and "goto" are java keywords, but neither is used. Serializable, Runnable, Externalizable, and Cloneable are all interfaces. Thread.run is a method. The keywords transient and volatile are field modifiers. |
| 8 | a b c d g i j k | byte short int long float double boolean char | |
| 9 | d | 4 | The literal, 1.0, is a double and can not be used to initialize a float without an explicit cast. |
| 10 | f | None of the Above | All of the declarations are legal. String b is a single quote followed by the letter A followed by another single quote. String C is the letter A. String D is the unicode character that represents the hexidecimal value abcd. |
| 11 | a | Prints: 1111111,177,127,7f | A byte is an 8 bit signed value. The left most bit is the sign bit. The sign bit is set to zero for positive numbers and is set to one for negative numbers. The most positive byte value is represented as a sign bit that is set to zero and all of the other bits set to one. The Integer.toBinaryString method does not print leading zeros. An eight bit binary value is represented as three octal digits. The first of the three digits represents the left most two bits of the binary value. In this case, the left most two bits are zero and one. The second octal digit represents the next three bits of the binary value. The last of the octal digits represents the right most three bits of binary value. Note that the Integer.toOctalString method does not print a leading zero as is required for an octal literal value. An eight bit binary value is represented as two hexadecimal digits. The left hex digit represents the left most bits of the binary value. The right hex digit represents the right most bits of the binary value. |
| 12 | b | Prints: 1010101,125,85,55 | A byte is an 8 bit signed value. The left most bit is the sign bit. The sign bit is set to zero for positive numbers. An eight bit binary value is represented as three octal digits. The first of the three digits represents the left most two bits of the binary value including any leading zeros. Please note that Integer.toBinaryString does not include the leading zeros. The second octal digit represents the next three bits of the binary value. The last of the octal digits represents the right most three bits of binary value. An eight bit binary value is represented as two hexadecimal digits. The left hex digit represents the left most bits of the binary value. The right hex digit represents the right most bits of the binary value. The decimal value of 85 can be converted to binary as follows. 85=64+16+4+1=01010101 |
| 13 | f | Compiler error. | A compiler error is generated by the attempt to assign the line feed character to char variable l. A unicode escape character should not be used to represent a linefeed or a carriage return. Instead, the escape sequence '\r' should be used to represent a carriage return, and '\n' should be used to represent a linefeed. |
| 14 | a b c e | char a = 0x0041; char b = '\u0041'; char c = 0101; char e = (char)-1; | The primitive char type is unsigned so a negative int can not be assigned to a char without an explicit cast. The result of the explicit cast is not a negative value. Instead, it is interpreted as a positive value that is very large. To be precise, it is the maximum value of the primitive char type. |
| 15 | f | Prints: 80000000,7fffffff | An int is a 32 bit signed value. The left most bit is the sign bit. The sign bit is zero for positive numbers and one for negative numbers. |
| 16 | e | Run-time exception | The index is incremented before the array access expression is evaluated so the first element accessed is at index one instead of zero. An ArrayIndexOutOfBoundsException is thrown when an attempt is made to access an element past the end of the array. |
| 17 | e f | Compiler error at line 5. Compiler error at line 6. | The non-static field x can not be referenced from within a static method. The local variable y has not been initialized. |
| 18 | c | Prints: 0null | The numeric sum of variables a, b, c, d, and e is zero. The zero is converted to a string and concatenated with s. |
| 19 | d | Prints: 127 -128 -1 0 | Bytes are stored as 8 bit two's complement signed integers. When an int primitive is cast to a byte, the three most significant bytes are discarded and only the least significant byte remains. The most significant bit of the remaining byte becomes the new sign bit. |